<!DOCTYPE html>
<html lang="zh-CN">

<head>
	<meta charset="UTF-8">
	<meta name="author" content="wangbo">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>
	<script>
		function foo({ x, y = 5 }) {
			console.log(x, y);
		}
		foo({}) // undefined, 5
		foo({ x: 1 }) // 1, 5
		foo({ x: 1, y: 2 }) // 1, 2

		function fetch(url, { body = '', method = 'GET', headers = {} }) {
			console.log(method);
		}
		fetch('http://example.com', {})
		// "GET"

		fetch('http://example.com')

		function fetch(url, { method = 'GET' } = {}) {
			console.log(method);
		}



		let foo = 'outer';
		function bar(func = x => foo) {
			let foo = 'inner';
			console.log(func()); // outer
		}
		bar();
	</script>
</body>

</html>